package com.situ.supermarket.service.impl;

import com.situ.supermarket.dao.PurchaseDao;
import com.situ.supermarket.entity.Goods;
import com.situ.supermarket.entity.Purchase;
import com.situ.supermarket.service.PurchaseService;
import com.situ.supermarket.vo.PurchaseVO;
import com.situ.supermarket.vo.TableVO;

import java.time.LocalDateTime;
import java.util.List;

public class PurchaseServiceImpl implements PurchaseService {
    PurchaseDao dao = new PurchaseDao();
    @Override
    public TableVO select(Integer page, Integer limit, String name, String employeeName) {
        List<PurchaseVO> list=dao.select(page,limit,name,employeeName);
        TableVO vo=new TableVO();
        vo.setCount(dao.count(name,employeeName));
        vo.setData(list);
        return vo;
    }

    @Override
    public void delete(Integer id) {
        dao.delete(id);
    }

    @Override
    public TableVO save(Purchase p) {
        if(p.getId()==null){
            dao.insert(p);
        }else {
            dao.update(p);
        }
        return null;
    }

    @Override
    public Purchase info(Integer id) {
        List<Purchase> list= dao.selectById(id);
        if(list.isEmpty()){
            return null;
        }else {
            return list.get(0);
        }
    }
}
